

# Person继承自object，或者可以省略
class Person(object):
    def __init__(self, name, age, gender):
        self.__name = name
        self.__age = age
        self.__gender = gender

    def update_name(self, name):
        self.__name = name

    def update_age(self, age):
        self.__age = age

    def update_gender(self, gender):
        self.__gender = gender

    # 必须返回string类型
    def __str__(self):
        # print("person info name: %s, age: %s, gender: %s" % (self.name, self.age, self.gender))
        return "person info name: %s, age: %s, gender: %s" % (self.__name, self.__age, self.__gender)


print("person", "-" * 20)
p = Person('lotus', 24, 'female')
print(p)                            # person info name: lotus, age: 24, gender: female
p.update_name('sky')
p.update_age(25)
p.update_gender('male')
print(p)                            # person info name: sky, age: 25, gender: male


# Teacher继承自Person
class Teacher(Person):
    def __init__(self, name, age, gender, occupation):
        # 初始化父类成员
        # super().__init__(name, age, gender)
        Person.__init__(self, name, age, gender)
        # 初始化本类成员
        self.occupation = occupation

    def teach(self):
        print("I am a teacher, I can teach, shut up and listen to me")

    def __str__(self):
        # print('teacher info, name: %s, age: %s, gender: %s, occupation: %s' % (self.__name, self.__age, self.__gender
        # , self.occupation))
        # 调用父类的共有函数
        print(super().__str__())
        return 'teacher info occupation: %s' % self.occupation


print("teacher", "-" * 20)
t = Teacher('lotus', 24, 'female', 'teacher')
print(t)
# person info name: lotus, age: 24, gender: female
# teacher info occupation: teacher
t.teach()                                               # I am a teacher, I can teach, shut up and listen to me

print('type_of_Person: %s ' % type(p))                  # <class '__main__.Person'>
print('type_of_Teacher: %s ' % type(t))                 # <class '__main__.Teacher'>

print('p is a Person: %s' % isinstance(p, Person))      # True
print('p is a Teacher: %s' % isinstance(p, Teacher))    # False
print('t is a Person: %s' % isinstance(t, Person))      # True
print('t is a Teacher: %s' % isinstance(t, Teacher))    # True


# Singer继承自Person
class Singer(Person):
    def __init__(self, name, age, gender, instrument):
        Person.__init__(self, name, age, gender)
        self.__instrument = instrument

    def sing(self):
        print('I am a singer, I can sing, we are the successors of communism')

    def __str__(self):
        print(super().__str__())
        return 'singer info instrument: %s' % self.__instrument


print("singer", "-" * 20)
sin = Singer("Beethoven", 68, 'male', "violin")
print(sin)
# person info name: Beethoven, age: 68, gender: male
# singer info instrument: violin


# Programmer继承自Person
class Programmer(Person):
    def __init__(self, name, age, gender, lan):
        Person.__init__(self, name, age, gender)
        self.__language = lan

    def sing(self):
        print('I am a programmer, I can program, I am good at python')

    def __str__(self):
        print(super().__str__())
        return 'programmer info language: %s' % self.__language


print("programmer", "-" * 20)
prog = Programmer("Stallman", 78, 'male', "GNU")
print(prog)
# person info name: Stallman, age: 78, gender: male
# programmer info language: GNU


# MySelf继承自Teacher，Singer，Programmer
class MySelf(Teacher, Singer, Programmer):
    def __init__(self, name, age, gender, occupation, ins, lan):
        Teacher.__init__(self, name, age, gender, occupation)
        Singer.__init__(self, name, age, gender, ins)
        Programmer.__init__(self, name, age, gender, lan)

    def __str__(self):
        print("myself info start -------------- ")
        print(super().__str__())
        return "myself info end -------------- "


myself = MySelf('Jesus', 99999, 'NULL', 'gold', 'Van', 'Python')
print(myself)
# 按照定义MySelf时的顺序的逆序调用各自的__str__方法
# myself info start --------------
# person info name: Jesus, age: 99999, gender: NULL
# programmer info language: Python
# singer info instrument: Van
# teacher info occupation: gold
# myself info end --------------
